define(function(require,exports,module) {
 //    require('./plug/hammer.min');
 //    require('./plug/lazyload_echo');
	// require('./plug/layer/layer');
    var myPub = require('./public');

	var oContactBossBtn = $('.js_contactBoss');     //联系商家信息按钮 js_contactBoss
    var oBossInfo = $('.js_bossInfo');              //商家信息 js_bossInfo
    var oBossName = $('.js_bossName');              //店家名字
    var oReasonList = $('.js_reasonList');          //取消原因选择
    var oCanOrderBtn = $('.js_cancelOrderBtn');     //取消订单按钮
    var oCanOrderInfo = $('.js_cancelOrder');       //取消订单信息
    var oUserMessage = $('.js_message').find('textarea');  //留言区域
    var oTrueGetBtn = $('.js_trueGetBtn');          //确认收货
    var oDelOrderBtn = $('.js_delOrderBtn');        //删除订单
    var oCancelApply = $('.js_cancelApply');        //取消申请
    var oHrefApply = $('.js_hrefApply');       //申请售后
    var oPreRefund = $('.js_preRefund');       //先行赔付
    var oRefundApply = $('.js_refundApply');       //申请售后
    var oNowPayBtn = $('.js_nowPayBtn');       //立即支付
    var oViewLogistics = $('.js_viewLogistics');       //查看物流

	var oOrderSlide = $('.js_orderInfoBox').find('.swiper-slide');


	//产品懒加载  异步加载 调用这个
    myPub.lazLoadingImgEcho();

	// 弹出商家信息列表
    oContactBossBtn.hammer().on('tap',function() {
        var styleTitle = 'width:100%;  border:none';
        var _sBossInfo= $('.js_bossInfo');
        var _index = oBossInfo.index(_sBossInfo);
        var _BossName = oBossName.eq(_index).text();

        myPub.HamstopPropaga();

        _sBossInfo.show();
        myPub.TipTitleLayer('联系商家: '+_BossName,styleTitle, _sBossInfo.html(),function() {
            _sBossInfo.hide();
        });
    });

    // 确认收货提示
    oTrueGetBtn.hammer().on('tap',function() {
    	var oId = $(this).attr("oId");
        var _cont = '<p class="delTipP" >亲！ 确定您已收到货物了吗？</p><span class="delTipSpan">确认收货后平台将会将货款打给商家</span>';

        myPub.HamstopPropaga();

        myPub.askLayer(_cont,function() {
            //确定收货
            G_JSON_GET('/member/order/receive',{"orderId": oId},function(data){
            	if (data.status == "success") {
                    //location.reload();
                    window.location.href = '/shop/goodsComment/comment/'+oId;
        		} else {
        			myPub.TipLayer(data.message);
        		}
        	});

            myPub.LayerCloseAll();
        },function() {
        },'no');
    });

    //跳转服务中心

    //申请退款
    oRefundApply.hammer().on('tap',function() {
        var _cont = '<p class="delTipP" >确认申请退款吗？</p>';
        var _this = $(this);
        myPub.HamstopPropaga();

        myPub.askLayer(_cont,function() {
            // 跳转售后
            var orderId = _this.attr("oId");
            window.location.href = '/shop/workOrder/showAfterSales/'+orderId+'?isRefund=true';
            myPub.LayerCloseAll();

        },function() {
            //alert('取消了');

        },'no');

    });

    //先行赔付
    oPreRefund.hammer().on('tap',function() {
        var _cont = '<p class="delTipP" >确认申请先行赔付吗？</p>';
        var _this = $(this);
        myPub.HamstopPropaga();

        myPub.askLayer(_cont,function() {
            // 跳转售后
            var orderId = _this.attr("oId");
            window.location.href = '/shop/workOrder/showPreRefund/'+orderId;
            myPub.LayerCloseAll();

        },function() {
            //alert('取消了');

        },'no');

    });


    //申请售后
    oHrefApply.hammer().on('tap',function() {
    	var _cont = '<p class="delTipP" >申请售后前请与商家协商好赔付金额?</p>';
        var _this = $(this);
        myPub.HamstopPropaga();

        myPub.askLayer(_cont,function() {
            // 跳转售后
            // var orderId = _this.attr("oId");
            // window.location.href = '/shop/workOrder/showAfterSales/'+orderId;

            //联系商家
            if(jswebcallcount != '' && jswebcallcount != null){
                if(jswebcallcount == 'sfddj'){
                    window.location.href = "http://sf.365webcall.com/chat/ChatWin3.aspx?settings=mw7mXbNN0m66066mz3Am66066mz3Am66066bz3Am6mmw0&LL=0"+jswebcallparam;
                }else{
                    window.location.href = "http://sf.365webcall.com/chat/ChatWinCorp.aspx?email="+jswebcallcount+"&accountid=sfddj&LL=0"+jsorderwebcallparam;
                }
                myPub.LayerCloseAll();
            }else {
                var styleTitle = 'width:100%;  border:none';
                var _sBossInfo= $('.js_bossInfo');
                var _index = oBossInfo.index(_sBossInfo);
                var _BossName = oBossName.eq(_index).text();

                myPub.HamstopPropaga();

                _sBossInfo.show();
                myPub.TipTitleLayer('联系商家: '+_BossName,styleTitle, _sBossInfo.html(),function() {
                    _sBossInfo.hide();
                });
            }

            //myPub.LayerCloseAll();

        },function() {
            //alert('取消了');
            // 跳转售后
            var orderId = _this.attr("oId");
            window.location.href = '/shop/workOrder/showAfterSales/'+orderId;
            myPub.LayerCloseAll();

        },'no',null,['联系商家','申请售后']);

    })



    // 售后订单被取消弹框
    oCancelApply.hammer().on('tap',function() {
        var _cont = '<p class="delTipP" >此订单正在售后处理</p><span class="delTipSpan">确认收货将取消售后申请</span>';

        myPub.HamstopPropaga();

        myPub.askLayer(_cont,function() {
            //alert('确定');
            myPub.LayerCloseAll();

        },function() {
            //alert('取消了');

        },'no');
    });

    //立即支付
    oNowPayBtn.hammer().on('tap',function() {
        var oId = $(this).attr("oId");
        submitPay(oId);
    });

    //查看物流
    oViewLogistics.hammer().on('tap',function() {
        var oId = $(this).attr("oId");
        window.location.href = "/member/order/express/" + oId;
    });


    // 删除订单
    oDelOrderBtn.hammer().on('tap',function() {
    	var oId = $(this).attr("oId");
        var _cont = '<p class="delTipP" >亲！ 您确定要删除此订单吗？</p><span class="delTipSpan">删除后此订单会永远消失</span>';
        myPub.askLayer(_cont,function() {
            // 判断删除店家
        	 G_JSON_GET('/member/order/delete',{"orderId": oId},function(data){
             	if (data.status == "success") {
             		window.location.href="/shop/pay/order_list";
         		} else {
         			myPub.TipLayer(data.message);
         		}
         	});
            myPub.LayerCloseAll();
        },function() {
        },'no');
    });



    // 取消订单
    oCanOrderBtn.on('click',function() {
    	var oId = $(this).attr("oId");
        var styleTitle = '请选择取消原因';
        myPub.askLayer(oCanOrderInfo.html(),function() {
        	var reasonType = $('.js_reasonList').find('li.active').html();
            var oUserMessage = $('.js_message').find('textarea').eq(1).val();
        	G_JSON_GET('/member/order/cancel',{"orderId": oId,"reasonType": reasonType,"reason": oUserMessage},function(data){
            	if (data.status == "success") {
            		location.reload();
        		} else {
        			myPub.TipLayer(data.message);
        		}
        	});
        },function() { myPub.LayerCloseAll(); },styleTitle,
        function() {
            // 弹框原因选择
            var _oReasonListLi = $('.js_reasonList').find('li');
            var oUserMessage = $('.js_message').find('textarea');  //留言区域
            var maxLWord = $('.js_wordmax');               //最大字数
            _oReasonListLi.hammer().off('tap');
            _oReasonListLi.hammer().on('tap',function() {
                _oReasonListLi.removeClass('active');
                $(this).addClass('active');
            });
            myPub.statInputNum(oUserMessage,maxLWord);
        });
    });

    // 原因选择
    oReasonList.find('li').hammer().on('tap',function() {
        oReasonList.find('li').removeClass('active');
        $(this).addClass('active');
    });

});